package com.qiaoba.file.qiniu.config;

import com.qiniu.storage.BucketManager;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * 七牛云 文件服务配置
 *
 * @author ailanyin
 * @date 2023-09-27 13:11:27
 */
@Configuration
@ComponentScan("com.qiaoba.file.qiniu")
public class QiniuOssConfig {

    @Value("${qiniu.oss.accessKey}")
    private String accessKey;

    @Value("${qiniu.oss.secretKey}")
    private String secretKey;

    @Bean
    public Auth auth() {
        return Auth.create(accessKey, secretKey);
    }

    @Bean
    public UploadManager uploadManager() {
        return new UploadManager(new com.qiniu.storage.Configuration());
    }

    @Bean
    public BucketManager bucketManager() {
        return new BucketManager(auth(), new com.qiniu.storage.Configuration());
    }
}
